﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using FreeProperty.Data;

namespace FreeProperty.Views.Main
{
    /// <summary>
    /// Summary description for LocationSuggest
    /// </summary>
    public class LocationSuggest : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            GetDistrictLocations(context);
        }
        private void GetDistrictLocations(HttpContext context)
        {
            StringBuilder sbNames = new StringBuilder();
            if (!string.IsNullOrEmpty(context.Request.QueryString["q"]) && !string.IsNullOrEmpty(context.Request.QueryString["q"])) // remember, 'q' is the query the autosuggest will pass
            {
                string districtId = context.Request.QueryString["did"];
                PropertyDesc oPropertyDesc = new PropertyDesc();
                oPropertyDesc.DistrictID = Convert.ToInt32(districtId);
                oPropertyDesc.Location = context.Request.QueryString["q"];
                List<string> lstLocations = oPropertyDesc.GetLocationForDostrict();
                foreach (var loc in lstLocations)
                {
                    sbNames.Append(loc).Append(Environment.NewLine);
                }
            }
            context.Response.Write(sbNames.ToString());
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}